﻿//Write a program to convert binary numbers to their decimal representation.

using System;
using System.Collections.Generic;

class BinaryToDecimal
{
    static void Main()
    {
        Console.WriteLine("Please, enter a binary number");
        string number = Console.ReadLine();

        Console.WriteLine("Decimal representation: {0}", ToDecimal(number));
    }

    static int ToDecimal(string number)
    {
        char[] array = number.ToCharArray();
        int result = 0;

        for (int i = array.Length - 1; i >= 0; i--)
        {
            result += ((array[i] - 48) * (int)(Math.Pow(2, i))); //-48 to convert char code number to int
        }

        return result;
    }
}
